package com.data_structure_algorithm.algorithm;

/**
 * @Author PABLO
 * @Date 2022/7/10 21:21
 * @Desc
 */
public class twoBin {

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 6, 9, 78, 569, 2369, 5289};
        int num = twoBIn(arr, 0, arr.length - 1, 78);
        System.out.println(num);
    }

    private static int twoBIn(int[] arr, int left, int right, int queryVal) {
        if (arr.length == 0) return -1;

        while (left <= right) {
            int mid = (left + right) / 2;
            if (arr[mid] == queryVal) return mid;
            else if (arr[mid] >= queryVal) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }


        return -1;
    }
}
